<template>
    <div>
        <van-form>
            <van-field v-model="form.mobile" label='手机号' :rules="[{'required':true,'message':'必须输入手机号'}]"/>
            <van-field v-model="form.password" label='密码' :rules="[{'required':true,'message':'必须输入密码'}]"/>   
            <van-button @click="add">登录</van-button> 
        </van-form>
    </div>
</template>

<script>
    export default {
        data(){
            return{
                form:{}
            }
        },
        methods:{
            add(){
                this.$axios.post('users/login',this.form).then(res=>{
                    if(res.data.code==200){
                        alert('登陆成功')
                        localStorage.setItem('id',res.data.id)
                        localStorage.setItem('mobile',res.data.mobile)
                        this.$router.push('userinfo')
                    }
                })
            }
        }
    }
</script>

<style scoped>

</style>